<%--
  Created by IntelliJ IDEA.
  User: 12459
  Date: 2024/11/7
  Time: 14:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8">
</head>
<body>

    <h1>登录成功,欢迎${sessionScope.user.userName}</h1>
    <form action="/provider/findByPage" method="get" accept-charset="UTF-8" >
        供货商名称:<input type="text" name="proName" value="${proName}">
        供货人:<input type="text" name="proContact" value="${proContact}" style="width: 100px">
        创建时间:<input type="datetime-local" name="startDate" value="${startDate}">-<input type="datetime-local"
                                                                                         name="endDate"
                                                                           value="${endDate}">
        <input type="submit" value="查询">
    </form>
<%--    <a href="/logout">退出登录</a>--%>
    <a href="/addProvider.jsp">新增供货商</a>
    <table border="1">
        <tr>
            <th>供货商ID</th>
            <th>供货商编码</th>
            <th>供货商名称</th>
            <th>供货商介绍</th>
            <th>供货人</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        <c:forEach items="${pageInfo.list}" var="provider">
            <tr pid = ${provider.id}>
                <td>${provider.id}</td>
                <td>${provider.proCode}</td>
                <td>${provider.proName}</td>
                <td title="${provider.proDesc}">
                    <c:choose>
                        <c:when test="${fn:length(provider.proDesc)>10}">
                            ${fn:substring(provider.proDesc,0 ,10 )}...
                        </c:when>
                        <c:otherwise>
                            ${provider.proDesc}
                        </c:otherwise>
                    </c:choose>
                </td>
                <td>${provider.proContact}</td>
                <td><fmt:formatDate value="${provider.creationDate}" pattern="yyyy.MM.dd HH:mm:ss"></fmt:formatDate> </td>
                <td><a href="/provider/findById?id=${provider.id}">修改</a>/<a class="del"
                                                                                      providerId="${provider.id}"
                                                                                      href="javascript:;">删除
                </a></td>
            </tr>
        </c:forEach>
    </table>
    <div class="box-footer">
        <div class="pull-left">
            <div class="form-group form-inline">
                总共${pageInfo.totalPage} 页，共${pageInfo.totalCount} 条数据。 每页
                <select id="pageSize">
                    <option value="5">5</option>
                    <option value="8">8</option>
                    <option value="10">10</option>
                </select> 条
            </div>
        </div>

        <div>
            <a
                    href="/provider/findByPage?currentPage=1&size=${pageInfo.size}&userName=${userName}&userCode
                    =${userCode}&startDate=${startDate}&endDate=${endDate}">首页</a>
            <a href="/provider/findByPage?currentPage=${pageInfo.currentPage-1}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">上一页</a>
            <c:forEach begin="1" end="${pageInfo.totalPage}" var="pageNum">
                <c:if test="${pageNum>=pageInfo.currentPage-2&&pageNum<=pageInfo.currentPage+2}">
                    <a href="/provider/findByPage?currentPage=${pageNum}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">${pageNum}</a>
                </c:if>
            </c:forEach>
            <a href="/provider/findByPage?currentPage=${pageInfo.currentPage+1}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">下一页</a>
            <a href="/provider/findByPage?currentPage=${pageInfo.totalPage}&size=${pageInfo.size}&userName=${userName}&userCode=${userCode}&startDate=${startDate}&endDate=${endDate}">尾页</a>
        </div>
    </div>
</body>
<script type="text/javascript" src="/js/jquery-3.7.1.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#pageSize").val("${pageInfo.size}")
        $("#pageSize").change(function () {
            location.href = "/provider/findByPage?currentPage=1&size="+$(this).val()+"&userName=${userName}&userCode& + &=${userCode}&startDate=${startDate}&endDate=${endDate}";
        });
        $(".del").click(function () {
            var bo = confirm("是否删除该数据!");
            if (bo){
                $.post("/provider/delete",{id:$(this).attr("providerId")},function (data) {
                    alert(data.message);
                    if (data.code === 200){
                        location.href="/provider/findByPage";
                    }
                },"json")
            }
        });

    })

</script>
</html>
